/*
package com.thread.threadfirst.marvel.citymaster.service;

import com.fugui.marvel.common.constants.CommonConstants;
import com.fugui.marvel.common.utils.DateCompare;
import com.fugui.marvel.service.citymaster.entity.Query;
import com.fugui.marvel.service.citymaster.enums.CityConfigStatus;
import com.fugui.marvel.service.citymaster.enums.IncomeChannel;
import com.fugui.marvel.service.citymaster.mapper.ApplyCityMasterMapper;
import com.fugui.marvel.service.citymaster.mapper.CityConfigMapper;
import com.fugui.marvel.service.citymaster.mapper.IncomeDetailsMapper;
import com.fugui.marvel.service.common.dto.ReturnT;
import com.fugui.marvel.service.common.dto.citymaster.*;
import com.fugui.marvel.service.common.service.dto.PageInfo;
import com.fugui.marvel.service.common.service.feign.client.user.FeignBrandConsoleServiceClient;
import com.fugui.marvel.service.common.service.feign.client.user.FeignBrandServiceClient;
import com.fugui.marvel.service.common.service.feign.client.user.FeignCityConsoleServiceClient;
import com.fugui.marvel.service.common.service.feign.client.user.FeignUserServiceClient;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;


@Service
@RestController
@Slf4j
@Transactional
public class CityConsoleServiceImpI {
 */
/*   Logger logger = LoggerFactory.getLogger(CityConsoleServiceImpI.class);*//*


    @Autowired
    CityConfigMapper cityConfigMapper;
    @Autowired
    ApplyCityMasterMapper applyCityMasterMapper;
    @Autowired
    IncomeDetailsMapper incomeDetailsMapper;
    @Autowired
    FeignUserServiceClient feignUserServiceClient;
    @Autowired
    FeignBrandServiceClient feignBrandServiceClient;
    @Autowired
    FeignBrandConsoleServiceClient feignBrandConsoleServiceClient;
    @Autowired
    FeignCityConsoleServiceClient feignCityConsoleServiceClient;
    */
/**
     * 修改城市在线状态
     * @param status
     * @param id
     * @return
     *//*

    @RequestMapping(method = RequestMethod.POST, value = "/m2.0/citymaster/updateCityStatus")
    @Transactional
    public Object  updateCityStatus(@RequestParam("status") Integer status,
                                    @RequestParam("id") Long id){
        Query cityConfigQuery = new Query();
        cityConfigQuery.put("status", status);
        cityConfigQuery.put("id", id);
        Map<String, Object> map = new HashMap<String, Object>();
        cityConfigMapper.updateCityStatus(cityConfigQuery);
        map.put(CommonConstants.RESP_CODE, CommonConstants.SUCCESS);
        map.put(CommonConstants.RESP_MESSAGE, "修改成功");
        return  map;
    }


    */
/**
     * 查询流水信息
     * @param brandId
     * @param channel
     * @return
     *//*

    @RequestMapping(method = RequestMethod.POST, value = "/m2.0/citymaster/queryIncomeDetail")
    public    com.fugui.marvel.service.common.service.dto.PageInfo<IncomeDetailConsoleDTO> queryIncomeDetail(@RequestParam(value = "brandId",required = false) Long brandId,
                                                               @RequestParam(value = "mobile",required = false) String mobile,
                                                               @RequestParam(value = "channel",required = false) Integer channel,
                                                               @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize",defaultValue = "20") Integer pageSize) {
        Query IncomeDetailsQuery = new Query();
        IncomeDetailsQuery.put("brandId", brandId);
        IncomeDetailsQuery.put("mobile", mobile);
        IncomeDetailsQuery.put("channel", channel);
        IncomeDetailsQuery.put("pageNum", pageNum);
        IncomeDetailsQuery.put("pageSize", pageSize);
        PageHelper.startPage(pageNum, pageSize);
        Page<IncomeDetailConsoleDTO> incomeDetailConsoleDTOS = incomeDetailsMapper.queryIncomeDetail(IncomeDetailsQuery);
        com.fugui.marvel.service.common.service.dto.PageInfo<IncomeDetailConsoleDTO> pageInfo =null;
        if (incomeDetailConsoleDTOS!=null){
            pageInfo = new com.fugui.marvel.service.common.service.dto.PageInfo<>(incomeDetailConsoleDTOS);
            List<IncomeDetailConsoleDTO> incomeDetailsDTOS = pageInfo.getList();
            if (incomeDetailsDTOS != null && incomeDetailsDTOS.size() > 0) {
                incomeDetailsDTOS.stream().forEach(x -> {
                    x.setChanelName(IncomeChannel.getEnumByKey(x.getChannel()== null ? -1 :x.getChannel()).getDescription());
                    x.setBrandName(feignBrandServiceClient.queryBrandById(x.getBrandId()).getName());
                    x.setFullname(feignUserServiceClient.queryUser(x.getUserId()) == null ? null : feignUserServiceClient.queryUser(x.getUserId()).getFullname());
                });
                return pageInfo;
            }
        }
        return pageInfo;
    }

    */
/**
     * 新增城市
     *//*

    @Transactional
    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/addCity")
    public ReturnT addCityByCityName(@RequestParam(value = "cityName",required = true)String cityName,
                            @RequestParam(value = "updateUser",required = false)String updateUser){
        Integer cityId=null;
        String cityid=feignCityConsoleServiceClient.findCityidByCity(cityName);
        try {
            if (cityid!=null){
                cityId= Integer.parseInt(cityid);
                CityConfigDTO cityConfigDTO=cityConfigMapper.findByCityId(cityId);
                if (cityConfigDTO==null){
                    int num=cityConfigMapper.addCityByCityName(cityId,cityName,updateUser);
                    if (num>0){
                        return new ReturnT("添加成功");
                    }else {
                        return new ReturnT(ReturnT.SUCCESS_CODE,"添加失败",null);
                    }
                }
                return new ReturnT<>(ReturnT.SUCCESS_CODE,"添加失败，已有此城市",null);
            }else {
                return new ReturnT(ReturnT.SUCCESS_CODE,"添加失败",null);
            }
        }catch (Exception e){
            throw new RuntimeException(e.getMessage());
        }

    }

    */
/**
     * 查询对应城市的历届城主信息
     * @param cityId
     * @return
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/querycorrectCityMasterPhone")
     public List<CityMasterConsoleCountDTO> querycorrectCityMasterPhone(@RequestParam(value = "cityId") Integer cityId) {
        List<CityMasterConsoleCountDTO> lists = new ArrayList<>();
         Query query = new Query();
        query.put("cityId", cityId);
        List<ApplyCityMasterDTO> result = applyCityMasterMapper.querycorrectCityMasterPhone(query);
        List<ApplyCityMasterDTO> result1 = applyCityMasterMapper.querycorrectCityMasterPhone1(query);
        List<ApplyCityMasterDTO> result2 = applyCityMasterMapper.querycorrectCityMasterPhone2(query);
        int salve = result.size();//正城主数量
        int falg = result1.size();//付城主1数量
        int falg2 = result2.size();//付城主2数量
        if(salve>=falg && salve>=falg2){
            //副城主是并行的关系 所以只需要三次判断就好了
            for (ApplyCityMasterDTO res: result) {
                salve = salve - 1;
                CityMasterConsoleCountDTO cityMasterConsoleCountDTO = new CityMasterConsoleCountDTO();
                cityMasterConsoleCountDTO.setMobile(res.getMobile());
                cityMasterConsoleCountDTO.setMobileTime(res.getCreateTime());
                cityMasterConsoleCountDTO.setSort(salve + 1);//加一保证不会出现0存在
                if(salve < result1.size()){
                    //当正城主的数量和付城主的数量相同的时候开始从付城主1取值
                    int cong = result1.size() - falg;
                    cityMasterConsoleCountDTO.setMobile1(result1.get(cong).getMobile());
                    cityMasterConsoleCountDTO.setMobile1Time(result1.get(cong).getCreateTime());
                    falg --;
                }
                if(salve < result2.size()){
                    //当正城主的数量和付城主的数量相同的时候开始从付城主2取值
                    int cong = result2.size() - falg2; //下次进来falg2--，然后出现差值进行取值
                    cityMasterConsoleCountDTO.setMobile2(result2.get(cong).getMobile());
                    cityMasterConsoleCountDTO.setMobile2Time(result2.get(cong).getCreateTime());
                    falg2 --;
                }
                lists.add(cityMasterConsoleCountDTO);
            }
        }else  if (falg>=salve && falg>=falg2){
            for (ApplyCityMasterDTO res: result1) {
                falg = falg - 1;
                CityMasterConsoleCountDTO cityMasterConsoleCountDTO = new CityMasterConsoleCountDTO();
                cityMasterConsoleCountDTO.setMobile1(res.getMobile());
                cityMasterConsoleCountDTO.setMobile1Time(res.getCreateTime());
                cityMasterConsoleCountDTO.setSort(falg + 1);//加一保证不会出现0存在
                if(falg < result.size()){
                    //当正城主的数量和付城主的数量相同的时候开始从付城主1取值
                    int cong = result.size() - salve;
                    cityMasterConsoleCountDTO.setMobile(result.get(cong).getMobile());
                    cityMasterConsoleCountDTO.setMobileTime(result.get(cong).getCreateTime());
                    salve --;
                }
                if(falg < result2.size()){
                    //当正城主的数量和付城主的数量相同的时候开始从付城主2取值
                    int cong = result2.size() - falg2; //下次进来falg2--，然后出现差值进行取值
                    cityMasterConsoleCountDTO.setMobile2(result2.get(cong).getMobile());
                    cityMasterConsoleCountDTO.setMobile2Time(result2.get(cong).getCreateTime());
                    falg2 --;
                }
                lists.add(cityMasterConsoleCountDTO);
            }
        }else  if (falg2>=salve && falg2>=falg){
            for (ApplyCityMasterDTO res: result2) {
                falg2 = falg2 - 1;
                CityMasterConsoleCountDTO cityMasterConsoleCountDTO = new CityMasterConsoleCountDTO();
                cityMasterConsoleCountDTO.setMobile2(res.getMobile());
                cityMasterConsoleCountDTO.setMobile2Time(res.getCreateTime());
                cityMasterConsoleCountDTO.setSort(falg2 + 1);//加一保证不会出现0存在
                if(falg2 < result1.size()){
                    //当正城主的数量和付城主的数量相同的时候开始从付城主1取值
                    int cong = result1.size() - falg;
                    cityMasterConsoleCountDTO.setMobile1(result1.get(cong).getMobile());
                    cityMasterConsoleCountDTO.setMobile1Time(result1.get(cong).getCreateTime());
                    falg --;
                }
                if(falg2 < result.size()){
                    //当正城主的数量和付城主的数量相同的时候开始从付城主2取值
                    int cong = result.size() - salve; //下次进来falg2--，然后出现差值进行取值
                    cityMasterConsoleCountDTO.setMobile(result.get(cong).getMobile());
                    cityMasterConsoleCountDTO.setMobileTime(result.get(cong).getCreateTime());
                    salve --;
                }
                lists.add(cityMasterConsoleCountDTO);
            }
    }
        return lists;
    }

    */
/**
     * 根据贴牌Id和城市名分页查询城市信息
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/findCityByBrandIdAndCityName")
    public PageInfo<CityConfigConsoleDTO> findCityByBrandIdAndCityName(@RequestParam(value = "brandId",required = false) Integer brandId,
                                                                @RequestParam(value = "cityName",required = false) String cityName,
                                                                @RequestParam(value = "cityStatus",required = false)Integer cityStatus,
                                                                @RequestParam(value = "pageNo",defaultValue = "1",required = false) Integer pageNo,
                                                                @RequestParam(value = "pageSizee",defaultValue = "20",required = false) Integer pageSizee){
        PageHelper.startPage(pageNo,pageSizee);
        com.github.pagehelper.Page<CityConfigConsoleDTO> cityConfigDTOList=cityConfigMapper.findCityByBrandIdAndCityName(brandId,cityName,cityStatus);
//        for (CityConfigConsoleDTO cityConfigConsoleDTO:cityConfigDTOList){
//            if (cityConfigConsoleDTO.getCityStatus()==0){
//                cityConfigConsoleDTO.setCityStatusName("初始化");
//            }
//            if (cityConfigConsoleDTO.getCityStatus()==1){
//                cityConfigConsoleDTO.setCityStatusName("待开放");
//            }
//            if (cityConfigConsoleDTO.getCityStatus()==2){
//                cityConfigConsoleDTO.setCityStatusName("已开放");
//            }
//            if (cityConfigConsoleDTO.getCityStatus()==3){
//                cityConfigConsoleDTO.setCityStatusName("已下线");
//            }
//        }
        com.fugui.marvel.service.common.service.dto.PageInfo<CityConfigConsoleDTO> pageInfo=null;
        if (cityConfigDTOList!=null){
            cityConfigDTOList.stream().forEach(item->{
                if (item.getCityStatus()==0){
//                    item.setCityStatusName("初始化");
                    item.setCityStatusName(CityConfigStatus.getEnumByKey(item.getCityStatus()).getDescription());
                }
                if (item.getCityStatus()==1){
//                    item.setCityStatusName("待开放");
                    item.setCityStatusName(CityConfigStatus.getEnumByKey(item.getCityStatus()).getDescription());
                }
                if (item.getCityStatus()==2){
//                    item.setCityStatusName("已开放");
                    item.setCityStatusName(CityConfigStatus.getEnumByKey(item.getCityStatus()).getDescription());
                }
                if (item.getCityStatus()==3){
//                    item.setCityStatusName("已下线");
                    item.setCityStatusName(CityConfigStatus.getEnumByKey(item.getCityStatus()).getDescription());
                }
            });
            pageInfo=new PageInfo<>(cityConfigDTOList);
            return pageInfo;
        }
        return pageInfo;

    }

    */
/**
     * 查询相关城市的城主时间
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/findCitymasterTime")
    public ReturnT<List<ApplyCityMasterConsoleDTO>> findCitymasterTime(@RequestParam(value = "cityId",required = true) Integer cityId,
                                                                @RequestParam(value = "cityMaster",required = true) String cityMaster,
                                                                @RequestParam(value = "cityDeputy1",required = true)String cityDeputy1,
                                                                @RequestParam(value = "cityDeputy2",required = true)String cityDeputy2){
        List<ApplyCityMasterConsoleDTO> citymasterTimes=cityConfigMapper.findCitymasterTime(cityId,cityMaster,cityDeputy1,cityDeputy2);
        citymasterTimes.stream().forEach(x->{
            if (x!=null && !x.equals("")){
                Integer cityType=x.getCityType();
                if (cityType==1){
                    x.setCityTypeName("正城主");
                }
                if (cityType==2){
                    x.setCityTypeName("副城主1");
                }
                if (cityType==3){
                    x.setCityTypeName("副城主2");
                }
            }
        });
        return new ReturnT<>(ReturnT.SUCCESS_CODE,"查询成功",citymasterTimes);
    }


    */
/**
     * 分页查询城市列表
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/findCityMaster")
    public com.fugui.marvel.service.common.service.dto.PageInfo<CityConfigMasterConsoleDTO> findCityMaster(@RequestParam(value = "brandId",required = false) Integer brandId,
                                                               @RequestParam(value = "cityName",required = false) String cityName,
                                                               @RequestParam(value = "cityStatus",required = false) Integer cityStatus,
                                                               @RequestParam(value = "mobile",required = false) String mobile,
                                                               @RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
                                                               @RequestParam(value = "pageSize",defaultValue = "20",required = false) Integer pageSize){
        DateCompare dateCompare=new DateCompare();
        PageHelper.startPage(pageNum,pageSize);
        //获得每页的城市信息
        com.github.pagehelper.Page<CityConfigMasterConsoleDTO> cityConfigMasterConsoleDTOList=cityConfigMapper.findCityMaster(brandId,cityName,cityStatus,mobile);
        //遍历每个城市数据
        for (CityConfigMasterConsoleDTO cityConfigMasterConsoleDTO:cityConfigMasterConsoleDTOList){
//            在线状态
            if (cityConfigMasterConsoleDTO.getCityStatus()==0){
//                cityConfigMasterConsoleDTO.setCityStatusName("初始化");
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
            if (cityConfigMasterConsoleDTO.getCityStatus()==1){
//                cityConfigMasterConsoleDTO.setCityStatusName("待开放");
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
            if (cityConfigMasterConsoleDTO.getCityStatus()==2){
//                cityConfigMasterConsoleDTO.setCityStatusName("已上线");
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
            if (cityConfigMasterConsoleDTO.getCityStatus()==3){
//                cityConfigMasterConsoleDTO.setCityStatusName("已下线");
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
//            判断城市状态，单个城市的所有城主手机号
            List<ApplyCityMasterConsoleDTO> applyCityMasterConsoleDTOS=cityConfigMasterConsoleDTO.getApplyCityMasterConsoleDTOList();
//            如果apply不为null
//            log.info("++++++++++apply长度+++++++++++++"+applyCityMasterConsoleDTOS.size());
            if (applyCityMasterConsoleDTOS.size()!=0){
                //该城市所有手机号
//                log.info(applyCityMasterConsoleDTOS.size()+"++++++app不为0+++++");
                String cityMaster=applyCityMasterConsoleDTOS.get(0).getCityMaster();
                String cityDeputy1=applyCityMasterConsoleDTOS.get(0).getCityDeputy1();
                String cityDeputy2=applyCityMasterConsoleDTOS.get(0).getCityDeputy2();
//                log.info("+++cityMasterMobile+++"+cityMaster+"==="+cityDeputy1+"====="+cityDeputy2+"======");
                //获得每个手机号的开始和结束时间
                Long cityId=cityConfigMasterConsoleDTO.getId();
                // 判断即将到期和暂无空位和有空位，不管有没有3个城主都走下面代码
                boolean tf=false;
                //调用获得时间的方法
//                String str=cityId+","+cityMaster+","+cityDeputy1+","+cityDeputy2;
////                Map map=new HashMap();
////                map.put("ids",str.split(","));
//                List list=new ArrayList();
//                list.add(str.split(","));
//                List<ApplyCityMasterDTO> applyCityMasterDTOList=cityConfigMapper.findCitymasterTime(list);
                List<ApplyCityMasterConsoleDTO> applyCityMasterConsoleDTOSList=cityConfigMapper.findCitymasterTime(cityId.intValue(),cityMaster,cityDeputy1,cityDeputy2);
                for (ApplyCityMasterConsoleDTO applyCityMasterConsoleDTO:applyCityMasterConsoleDTOSList) {
                    //遍历每个手机号的到期时间，来判断从数据库获取的手机号是否已过期，过期不显示
                    Date expiryTime1=applyCityMasterConsoleDTO.getExpiryTime();
                    //NowTime-到期时间
                    String time=dateCompare.subtract_date(expiryTime1.getTime());
//                    log.info("mobile时差："+time);
                    String[] days=time.split("天");
                    int day=Integer.parseInt(days[0]);
                    String hours=time.substring(time.indexOf("天")+1,time.indexOf("小"));
                    String minutes=time.substring(time.indexOf("时")+1,time.indexOf("分"));
//                    log.info("!!!!!!!"+day+"天"+hours+"时"+minutes+"分");
                    if (day>0){
                        //已过期用户，将手机号为""，有空位
                        String gqsjh=applyCityMasterConsoleDTO.getMobile();
                        if (cityMaster!=null && cityMaster.equals(gqsjh)){
                            applyCityMasterConsoleDTOS.get(0).setCityMaster(null);
                        }
                        if (cityDeputy1!=null && cityDeputy1.equals(gqsjh)){
                            applyCityMasterConsoleDTOS.get(0).setCityDeputy1(null);
                        }
                        if (cityDeputy2!=null && cityDeputy2.equals(gqsjh)){
                            applyCityMasterConsoleDTOS.get(0).setCityDeputy2(null);
                        }
//                        cityConfigMasterConsoleDTO.setCityState("有空位");
                    }else if (day==0){
                        //再判断小时和分钟，即将过期和已过期
                        int hour=Integer.parseInt(hours);
                        int minute=Integer.parseInt(minutes);
                        if (hour>0){
                            //已过期
                            String gqsjh=applyCityMasterConsoleDTO.getMobile();
                            if (cityMaster!=null && cityMaster.equals(gqsjh)){
                                applyCityMasterConsoleDTOS.get(0).setCityMaster(null);
                            }
                            if (cityDeputy1!=null && cityDeputy1.equals(gqsjh)){
                                applyCityMasterConsoleDTOS.get(0).setCityDeputy1(null);
                            }
                            if (cityDeputy2!=null && cityDeputy2.equals(gqsjh)){
                                applyCityMasterConsoleDTOS.get(0).setCityDeputy2(null);
                            }
//                            cityConfigMasterConsoleDTO.setCityState("有空位");
                        }else if (hour==0){
                            if (minute>=0){
                                //已过期
                                String gqsjh=applyCityMasterConsoleDTO.getMobile();
                                if (cityMaster!=null && cityMaster.equals(gqsjh)){
                                    applyCityMasterConsoleDTOS.get(0).setCityMaster(null);
                                }
                                if (cityDeputy1!=null && cityDeputy1.equals(gqsjh)){
                                    applyCityMasterConsoleDTOS.get(0).setCityDeputy1(null);
                                }
                                if (cityDeputy2!=null && cityDeputy2.equals(gqsjh)){
                                    applyCityMasterConsoleDTOS.get(0).setCityDeputy2(null);
                                }
//                                cityConfigMasterConsoleDTO.setCityState("有空位");
                            }else {
                                //即将过期
//                                    cityConfigMasterConsoleDTO.setCityState("即将到期");
                                tf=true;
                            }
                        }else{
                            //即将过期
//                                cityConfigMasterConsoleDTO.setCityState("即将到期");
                            tf=true;
                        }
                    }else if (day<0){
                        if (Math.abs(day)<=3){
                            //即将过期
//                                cityConfigMasterConsoleDTO.setCityState("即将到期");
                            tf=true;
                        }//没有过期
                    }
                }

                //如果不够3个，则有空位
                if (applyCityMasterConsoleDTOS.get(0).getCityMaster()==null || applyCityMasterConsoleDTOS.get(0).getCityDeputy1()==null || applyCityMasterConsoleDTOS.get(0).getCityDeputy2()==null){
                    cityConfigMasterConsoleDTO.setCityState("有空位");
                }else if (tf==true){
                    //即将过期
                    cityConfigMasterConsoleDTO.setCityState("即将过期");
                }else {
                    cityConfigMasterConsoleDTO.setCityState("暂无空位");
                }

            }else {
                //从数据库中获取到的城主信息长度为0
                cityConfigMasterConsoleDTO.setCityState("有空位");
//                log.info("++++++++++++++apply为0+++++++++++++");
            }

            //城市总收益
            if (cityConfigMasterConsoleDTO.getIncomeDetailsMasterConsoleDTOS().size()>0){
                Long cityId=cityConfigMasterConsoleDTO.getId();
                IncomeDetailsMasterConsoleDTO incomeDetailsMasterConsoleDTO=cityConfigMapper.findCityEarningsSum(cityId.intValue(),brandId);
                if (incomeDetailsMasterConsoleDTO!=null){
                    BigDecimal earningsSum=incomeDetailsMasterConsoleDTO.getEarningsSum();
                    cityConfigMasterConsoleDTO.getIncomeDetailsMasterConsoleDTOS().get(0).setEarningsSum(earningsSum);
                }
            }

        }
        PageInfo<CityConfigMasterConsoleDTO> pageInfo=new PageInfo<>(cityConfigMasterConsoleDTOList);
        return pageInfo;
    }



    */
/**
     * 分页查询城市列表2
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/findCityMasterr")
    public com.fugui.marvel.service.common.service.dto.PageInfo<CityConfigMasterConsoleDTO> findCityMasterr(@RequestParam(value = "brandId",required = false) Integer brandId,
                                                                                                           @RequestParam(value = "cityName",required = false) String cityName,
                                                                                                           @RequestParam(value = "cityStatus",required = false) Integer cityStatus,
                                                                                                           @RequestParam(value = "mobile",required = false) String mobile,
                                                                                                           @RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
                                                                                                           @RequestParam(value = "pageSize",defaultValue = "20",required = false) Integer pageSize){
        DateCompare dateCompare=new DateCompare();
        PageHelper.startPage(pageNum,pageSize);
        //获得每页的城市信息
        com.github.pagehelper.Page<CityConfigMasterConsoleDTO> cityConfigMasterConsoleDTOList=cityConfigMapper.findCityMasterr(brandId,cityName,cityStatus,mobile);
        //遍历每个城市数据
        for (CityConfigMasterConsoleDTO cityConfigMasterConsoleDTO:cityConfigMasterConsoleDTOList){
//            在线状态
            if (cityConfigMasterConsoleDTO.getCityStatus()==0){
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
            if (cityConfigMasterConsoleDTO.getCityStatus()==1){
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
            if (cityConfigMasterConsoleDTO.getCityStatus()==2){
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
            if (cityConfigMasterConsoleDTO.getCityStatus()==3){
                cityConfigMasterConsoleDTO.setCityStatusName(CityConfigStatus.getEnumByKey(cityConfigMasterConsoleDTO.getCityStatus()).getDescription());
            }
//            判断城市状态，单个城市的所有城主手机号
            ApplyCityMasterConsoleDTO applyCityMasterConsoleDTOS=cityConfigMasterConsoleDTO.getApplyCityMasterConsoleDTO();
//            如果apply不为null
//            log.info("++++++++++apply长度+++++++++++++"+applyCityMasterConsoleDTOS.size());
            if (applyCityMasterConsoleDTOS!=null){
                //该城市所有手机号
//                log.info(applyCityMasterConsoleDTOS.size()+"++++++app不为0+++++");
                String cityMaster=applyCityMasterConsoleDTOS.getCityMaster();
                String cityDeputy1=applyCityMasterConsoleDTOS.getCityDeputy1();
                String cityDeputy2=applyCityMasterConsoleDTOS.getCityDeputy2();
//                log.info("+++cityMasterMobile+++"+cityMaster+"==="+cityDeputy1+"====="+cityDeputy2+"======");
                //获得每个手机号的开始和结束时间
                Long cityId=cityConfigMasterConsoleDTO.getId();
                // 判断即将到期和暂无空位和有空位，不管有没有3个城主都走下面代码
                boolean tf=false;
                //调用获得时间的方法
                List<ApplyCityMasterConsoleDTO> applyCityMasterConsoleDTOList=cityConfigMapper.findCitymasterTime(cityId.intValue(),cityMaster,cityDeputy1,cityDeputy2);
                for (ApplyCityMasterConsoleDTO applyCityMasterConsoleDTO:applyCityMasterConsoleDTOList) {
                    //遍历每个手机号的到期时间，来判断从数据库获取的手机号是否已过期，过期不显示
                    Date expiryTime1=applyCityMasterConsoleDTO.getExpiryTime();
                    //NowTime-到期时间
                    String time=dateCompare.subtract_date(expiryTime1.getTime());
//                    log.info("mobile时差："+time);
                    String[] days=time.split("天");
                    int day=Integer.parseInt(days[0]);
                    String hours=time.substring(time.indexOf("天")+1,time.indexOf("小"));
                    String minutes=time.substring(time.indexOf("时")+1,time.indexOf("分"));
//                    log.info("!!!!!!!"+day+"天"+hours+"时"+minutes+"分");
                    if (day>0){
                        //已过期用户，将手机号为""，有空位
                        String gqsjh=applyCityMasterConsoleDTO.getMobile();
                        if (cityMaster!=null && cityMaster.equals(gqsjh)){
                            applyCityMasterConsoleDTOS.setCityMaster(null);
                        }
                        if (cityDeputy1!=null && cityDeputy1.equals(gqsjh)){
                            applyCityMasterConsoleDTOS.setCityDeputy1(null);
                        }
                        if (cityDeputy2!=null && cityDeputy2.equals(gqsjh)){
                            applyCityMasterConsoleDTOS.setCityDeputy2(null);
                        }
//                        cityConfigMasterConsoleDTO.setCityState("有空位");
                    }else if (day==0){
                        //再判断小时和分钟，即将过期和已过期
                        int hour=Integer.parseInt(hours);
                        int minute=Integer.parseInt(minutes);
                        if (hour>0){
                            //已过期
                            String gqsjh=applyCityMasterConsoleDTO.getMobile();
                            if (cityMaster!=null && cityMaster.equals(gqsjh)){
                                applyCityMasterConsoleDTOS.setCityMaster(null);
                            }
                            if (cityDeputy1!=null && cityDeputy1.equals(gqsjh)){
                                applyCityMasterConsoleDTOS.setCityDeputy1(null);
                            }
                            if (cityDeputy2!=null && cityDeputy2.equals(gqsjh)){
                                applyCityMasterConsoleDTOS.setCityDeputy2(null);
                            }
//                            cityConfigMasterConsoleDTO.setCityState("有空位");
                        }else if (hour==0){
                            if (minute>=0){
                                //已过期
                                String gqsjh=applyCityMasterConsoleDTO.getMobile();
                                if (cityMaster!=null && cityMaster.equals(gqsjh)){
                                    applyCityMasterConsoleDTOS.setCityMaster(null);
                                }
                                if (cityDeputy1!=null && cityDeputy1.equals(gqsjh)){
                                    applyCityMasterConsoleDTOS.setCityDeputy1(null);
                                }
                                if (cityDeputy2!=null && cityDeputy2.equals(gqsjh)){
                                    applyCityMasterConsoleDTOS.setCityDeputy2(null);
                                }
//                                cityConfigMasterConsoleDTO.setCityState("有空位");
                            }else {
                                //即将过期
//                                    cityConfigMasterConsoleDTO.setCityState("即将到期");
                                tf=true;
                            }
                        }else{
                            //即将过期
//                                cityConfigMasterConsoleDTO.setCityState("即将到期");
                            tf=true;
                        }
                    }else if (day<0){
                        if (Math.abs(day)<=3){
                            //即将过期
//                                cityConfigMasterConsoleDTO.setCityState("即将到期");
                            tf=true;
                        }//没有过期
                    }
                }

                //如果不够3个，则有空位
                if (applyCityMasterConsoleDTOS.getCityMaster()==null || applyCityMasterConsoleDTOS.getCityDeputy1()==null || applyCityMasterConsoleDTOS.getCityDeputy2()==null){
                    cityConfigMasterConsoleDTO.setCityState("有空位");
                }else if (tf==true){
                    //即将过期
                    cityConfigMasterConsoleDTO.setCityState("即将过期");
                }else {
                    cityConfigMasterConsoleDTO.setCityState("暂无空位");
                }

            }else {
                //从数据库中获取到的城主信息长度为0
                cityConfigMasterConsoleDTO.setCityState("有空位");
//                log.info("++++++++++++++apply为0+++++++++++++");
            }

            //城市总收益
            if (cityConfigMasterConsoleDTO.getIncomeDetailsMasterConsoleDTO()!=null){
                Long cityId=cityConfigMasterConsoleDTO.getId();
                IncomeDetailsMasterConsoleDTO incomeDetailsMasterConsoleDTO=cityConfigMapper.findCityEarningsSum(cityId.intValue(),brandId);
                if (incomeDetailsMasterConsoleDTO!=null){
                    BigDecimal earningsSum=incomeDetailsMasterConsoleDTO.getEarningsSum();
                    cityConfigMasterConsoleDTO.getIncomeDetailsMasterConsoleDTO().setEarningsSum(earningsSum);
                }
            }

        }
        PageInfo<CityConfigMasterConsoleDTO> pageInfo=new PageInfo<>(cityConfigMasterConsoleDTOList);
        return pageInfo;
    }



    */
/**
     * 查询某个城市总收益
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/findCityEarningsSum")
    public IncomeDetailsMasterConsoleDTO findCityEarningsSum(@RequestParam(value = "cityId",required = true)Integer cityId, @RequestParam(value = "brandId",required = false)Integer brandId){
        return cityConfigMapper.findCityEarningsSum(cityId,brandId);
    }


    */
/**
     *查询相关城市收益明细
     *//*

    @RequestMapping(method = RequestMethod.POST,value = "/m2.0/citymaster/findCityEarningsDetail")
    public com.fugui.marvel.service.common.service.dto.PageInfo<IncomeDetailConsoleDTO> findCityEarningsDetail(@RequestParam(value = "cityId", required = true) Integer cityId,
                                                                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                                                               @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        Page<IncomeDetailConsoleDTO> incomeDetailConsoleDTOS=cityConfigMapper.findCityEarningsDetail(cityId);
        com.fugui.marvel.service.common.service.dto.PageInfo pageInfo=null;
        if (incomeDetailConsoleDTOS!=null){
            pageInfo=new PageInfo(incomeDetailConsoleDTOS);
            List<IncomeDetailConsoleDTO> incomeDetailConsoleDTOList=pageInfo.getList();
            if (incomeDetailConsoleDTOList!=null && incomeDetailConsoleDTOList.size()>0){
                incomeDetailConsoleDTOList.stream().forEach(x->{
                    x.setChanelName(IncomeChannel.getEnumByKey(x.getChannel()==null ? -1 : x.getChannel()).getDescription());
                    x.setFullname(feignUserServiceClient.queryUser(x.getUserId().longValue())==null ? null :feignUserServiceClient.queryUser(x.getUserId().longValue()).getFullname());
                    x.setBrandName(feignBrandServiceClient.queryBrandById(x.getBrandId()).getName());
                });
                return pageInfo;
            }
        }
        return pageInfo;
    }


}
*/
